import React, { Component } from "react";

class Moxing extends Component {
  state = {
    msg: "林杨",
  };
  dianji0 = () => {
    console.log("子组件开始传值");
    this.props.dianji(this.state.msg);
  };
  render() {
    return (
      <div>
        <h3>{this.props.msg}</h3>
        <button onClick={this.dianji0}>给父组件传值</button>
      </div>
    );
  }
}
export default class Ap extends Component {
  dianji = (zhi) => {
    console.log("子组件传值给父组件");

    this.setState({
      xingming: zhi,
    });
  };
  state = {
    xingming: "",
  };
  render() {
    return (
      <div>
        <h3>子组件传来的值：{this.state.xingming}</h3>
        <Moxing msg="昊辰" dianji={this.dianji}></Moxing>
      </div>
    );
  }
}
